﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Unicode;
using System.Collections;
using System.Threading;

namespace ScheduleUtil
{
    /// <summary>
    /// 时间片段
    /// </summary>
    public class TimeFlag
    {
        /// <summary>
        /// 开机时间
        /// </summary>
        public string open { get; set; } = "";
        /// <summary>
        /// 关机时间
        /// </summary>
        public string close { get; set; } = "";
        /// <summary>
        /// 判断是否在时间段内
        /// </summary>
        /// <param name="addMinute"></param>
        /// <param name="subMinute"></param>
        /// <returns></returns>
        public bool TimeIn(int addMinute = 0, int subMinute = 0)
        {
            if (open == null || open.Length <= 0 || close == null || close.Length <= 0)
            { 
                return false;
            }

            //判断当前时间是否在工作时间段内
            DateTime timeOpen = DateTime.Parse(open);
            DateTime timeClose = DateTime.Parse(close);

            //时间点矛盾的剔除
            if (timeClose < timeOpen)
            {
                return false;
            }

            DateTime dt = DateTime.Now;
            if (dt >= timeOpen.AddMinutes(-1 * addMinute) && dt <= timeClose.AddMinutes(subMinute))
            {
                return true;
            }

            return false;
        }
    }
}
